//
// Created by zhuanding on 2023/5/25.
//

#include <cstdlib>
#include "../01-preface/Status.h"

typedef struct LinkNode {
    ElemType data;   // 数据域
    struct LinkNode *next;  // 指针域
} *LinkStack;

void InitStack_L(LinkStack &S) {
    S = NULL;
}


int StackLength_L(LinkStack S) {
    int k = 0;
    LinkStack p = S;
    while (p) {
        k++;
        p = p->next;
    }
    return k;
}


bool Push_L(LinkStack &S, ElemType e) {
    LinkStack p;
    p = (LinkNode *) malloc(sizeof(LinkNode));
    if (p == NULL) return false;
    p->data = e;
    p->next = S;
    S = p;
    return true;
}

bool Pup_L(LinkStack &S, ElemType &e) {
    LinkStack p;
    if (S) {
        p = S;
        S = S->next;
        e = p->data;
        free(p);
        return true;
    } else {
        return false;
    }
}

bool StackEmpty_L(LinkStack S) {
    if (S)
        return true;
    else
        return false;
}


void DestroyStack_L(LinkStack &S) {
    LinkStack p, q;
    p = S;
    while (p) {
        q = p;
        p = p->next;
        free(q);
    }
    S = NULL;
}

int main() {
    LinkStack S;

    InitStack_L(S);
    printf("%p\n", &S);
    return 0;
}


